package apis.amapv2.com.threadpool;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;


public class MainActivity extends AppCompatActivity {

    private static final String TAG = MainActivity.class.getSimpleName();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        testThreadPool();
    }

    private void testThreadPool() {
        //参数：表示线程的个数
        //1、创建线程池对象。
        ExecutorService executorService = Executors.newFixedThreadPool(2);
        //2、创建Runnable实例。3、提交Runnable实例。
        executorService.submit(new Runnable() {
            @Override
            public void run() {
                Log.e(TAG,"thread one");
            }
        });
        executorService.submit(new Runnable() {
            @Override
            public void run() {
                Log.e(TAG,"thread two");
            }
        });
        //4、关闭线程池
        executorService.shutdown();
    }
}
